package com.cs.controller;

import com.cs.context.BaseContext;
import com.cs.dto.AnnouncementPageQueryDTO;
import com.cs.result.PageResult;
import com.cs.result.Result;
import com.cs.service.AnnouncementService;
import com.cs.service.CourseService;
import com.cs.service.impl.AnnouncementServiceImpl;
import com.cs.vo.CourseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course")
@Api(tags = "课程操作")
@CrossOrigin//解决跨域问题
@Slf4j
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 获取所有课程
     * @return
     */
    @GetMapping("/getAllCourse")
    @ApiOperation("获取所有课程")
    public Result<List<CourseVO>> getAllCourse(){
        log.info("获取所有课程");
        List<CourseVO> courseVOList = courseService.getAllCourse();
        return Result.success(courseVOList);
    }

    /**
     * 根据课程id获取课程
     * @param id
     * */
    @GetMapping("/getCourseById/{id}")
    @ApiOperation("根据课程id获取课程")
    public Result<CourseVO> getCourseById(@PathVariable("id") Integer id){
        log.info("根据课程id获取课程,id:{}",id);
        CourseVO courseVO = courseService.getCourseById(id);
        return Result.success(courseVO);
    }

    /**
     * 根据课程id添加课程
     * @param courseId
     * @return
     */
    @PostMapping("/addCourseById")
    @ApiOperation("根据课程id添加课程")
    public Result addCourseById (@RequestParam Integer courseId){
        log.info("根据课程id添加课程,courseId:{}",courseId);
        return courseService.addCourseById(courseId);
    }

    /**
     * 查询个人课程表
     * @param studentId 学生ID
     * @return 课程列表
     */
    @GetMapping("/getPersonalCourseSchedule")
    @ApiOperation("查询个人课程表")
    public Result<List<CourseVO>> getPersonalCourseSchedule() {
        log.info("查询个人课程表, studentId: {}", BaseContext.getCurrentId());
        List<CourseVO> courseVOList = courseService.getPersonalCourseSchedule(BaseContext.getCurrentId());
        return Result.success(courseVOList);
    }
}
